﻿using System.ComponentModel;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using GSSoftSL.ViewModel;
using GSSoftSL.Web.Models;

namespace GSSoftSL.Views
{
    /// <summary>
    /// Description for LopChiTiet.
    /// </summary>
    public partial class LopChiTietEdit : ChildWindow
    {
        //private EntityState _state = EntityState.New;
        private KhoaHocChiTietViewModel _vm;
        public bool IsSubmit { get; set; }

        /// <summary>
        /// Initializes a new instance of the LopChiTiet class.
        /// </summary>
        public LopChiTietEdit(KhoaHocChiTiet model, Phong[] phongs, CaHoc[] caHocs)
        {
            InitializeComponent();
            _vm = new KhoaHocChiTietViewModel(model, phongs, caHocs);
            DataContext = _vm;
            this.Closing += LopChiTietEdit_Closing;
        }

        private void LopChiTietEdit_Closing(object sender, CancelEventArgs e)
        {
            //dataForm.CommitEdit();
            //dataForm.CancelEdit();
        }

        /*private void dataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
        {
            if (e.EditAction == DataFormEditAction.Cancel)
                IsSubmit = false;
            else
            {
                IsSubmit = true;
                _vm.CopyValue();
            }
            dataForm.CancelEdit();
            this.Close();
        }*/

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
        	if (_vm.Proxy.Phong == null)
        	{
        	    MessageWindow.CreateNew("Bạn vui lòng chọn phòng học.");
                return;
        	}
            if (_vm.Proxy.CaHoc == null)
            {
                MessageWindow.CreateNew("Bạn vui lòng chọn ca học.");
                return;
            }
            IsSubmit = true;
            _vm.CopyValue();
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            IsSubmit = false;
            this.Close();
        }


    }
}